#include "common.h"

#include "threadpool.h"

int TASK1(void *arg)
{
    printf("TASK1 %ld\r\n", pthread_self());
    sleep(1);
}

void TASK2(void *arg)
{
    printf("TASK2 %s", (char *)arg);
    sleep(1);
}

int main(int argc, char const *argv[])
{
    ThreadPool_Handler pool = ThreadPool_Init(6, 3);
    if(NULL == pool) return -1;

    sleep(1);

    ThreadPool_Remove_Threads(pool, 6);

    printf("ThreadPool_TotalThreads : %d\r\n", ThreadPool_TotalThreads(pool));
    printf("ThreadPool_ActiveThreads : %d\r\n", ThreadPool_ActiveThreads(pool));

    sleep(1);

    ThreadPool_Insert_Threads(pool, 6);

    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK1, NULL);
    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK2, (void *)"HELLO1\r\n");

    sleep(1);

    ThreadPool_Remove_Threads(pool, 4);

    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK1, NULL);
    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK2, (void *)"HELLO2\r\n");

    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK1, NULL);
    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK2, (void *)"HELLO3\r\n");

    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK1, NULL);
    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK2, (void *)"HELLO4\r\n");

    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK1, NULL);
    ThreadPool_Add_Task_Tail(pool, (TaskFunc)TASK2, (void *)"HELLO5\r\n");

    sleep(1);

    printf("ThreadPool_TotalThreads : %d\r\n", ThreadPool_TotalThreads(pool));
    printf("ThreadPool_ActiveThreads : %d\r\n", ThreadPool_ActiveThreads(pool));

    ThreadPool_Destory(pool);

    return 0;
}





